﻿using Cloud.BLL;
using Cloud.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Three_Managerment_P0501_shyq : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录信息已失效，请重新登录'); window.parent.location.href='/index.html'</script>");

            }



            if (IsPostBack)
            {

            }
            else
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                Problem activity = ProblemManager.FindById(id);
                if (activity != null)
                {
                    if (activity.Secrecy.Equals("0"))
                    {
                        this.xm.InnerText = activity.Appeal_name.ToString();
                        this.lxfs.InnerText = activity.Appeal_tel;
                    }
                    else
                    {
                        //this.xm.InnerText = "****信息已加密****";
                        //this.lxfs.InnerText = "****信息已加密****";
                        this.xm.InnerText = activity.Appeal_name.ToString();
                        this.lxfs.InnerText = activity.Appeal_tel;
                    }
                    this.lab_xbsj.InnerText = activity.Xbtime == new DateTime(1900, 01, 01, 00, 00, 00) ? "无限办时间" : activity.Xbtime.ToString();

                    this.sjbh.InnerText = activity.Appealid.ToString();
                    this.sbsj.InnerText = activity.Regtime.ToString();
                    this.sqly.InnerText = SourcesManager.FindById(activity.Source_id) == null ? "" : SourcesManager.FindById(activity.Source_id).Name;
                    this.sqlx.InnerText = AscriptionManager.FindById(activity.Ascription_id) == null ? "" : AscriptionManager.FindById(activity.Ascription_id).Name;
                    this.gs.InnerText = AscriptionManager.FindById(activity.Ascription_id) == null ? "" : AscriptionManager.FindById(activity.Ascription_id).Name;
                    this.dl.InnerText = Classification_Appeal1Manager.FindById(activity.Appeal_type_id) == null ? "" : Classification_Appeal1Manager.FindById(activity.Appeal_type_id).Name;
                    this.xl.InnerText = Classification_Appeal2Manager.FindById(activity.Xialei) == null ? "" : Classification_Appeal2Manager.FindById(activity.Xialei).Name;
                    this.zrdwid.InnerText = DWManager.FindById(activity.Zrdwid) == null ? "" : DWManager.FindById(activity.Zrdwid).DWMC;
                    //this.yx.InnerText = activity.Appeal_email;
                    this.times.InnerText = select_yqz(activity.Appealid);
                    this.bt.InnerText = activity.Title;
                    this.nr.InnerText = activity.Context;
                    this.gh.InnerText = activity.Jobnum.ToString();
                    this.sqyq.InnerText = YqsqManager.FindById(activity.Id) == null ? "否" : "是";
                    IList<Problem_historic2> Listph2 = new List<Problem_historic2>();
                    Listph2 = Problem_historic2Manager.FindBysj(activity.Appealid);
                    if (Listph2.Count > 0)
                    {
                        this.nbyj.InnerText = Listph2[0].Blyj;
                    }

                    if (Listph2.Count > 1)
                    {
                        for (int i = 0; i < Listph2.Count; i++)
                        {
                            this.bljg.InnerText += Listph2[i].Blyj.ToString() + " \n ";
                        }
                    }


                    if (activity.Handle_type == 0 || activity.Handle_type == 1 || activity.Handle_type == 2)
                    {
                        if (activity.Xbtime.ToString("yyyy-MM-dd HH:mm:ss").Equals("1900-01-01 00:00:00"))
                        {
                            this.is_cs.InnerText = "否";
                        }
                        else
                        {
                            if (Convert.ToDateTime(activity.Xbtime) < DateTime.Now)
                            {
                                this.is_cs.InnerText = "是";
                            }
                            else
                            {
                                this.is_cs.InnerText = "否";
                            }
                        }


                    }
                    else
                    {

                        this.is_cs.InnerText = "否";
                    }

                    if (activity.Current_ld == 0)
                    {
                        dbm.InnerText = "一级部门办理中";
                    }
                    else if (activity.Current_ld == 1)
                    {
                        dbm.InnerText = "二级部门办理中";
                    }
                    else if (activity.Current_ld == 2)
                    {
                        dbm.InnerText = "三级部门办理中";
                    }
                    this.repeater.DataSource = Problem_historic2Manager.FindBysj(activity.Appealid);
                    this.repeater.DataBind();
                    this.div.Visible = false;

                }

                //int id = Convert.ToInt32(Request.QueryString["id"]);
                //Problem activity = ProblemManager.FindById(id);
                //if (activity != null)
                //{
                //    if (activity.Secrecy.Equals("0"))
                //    {
                //        this.xm.InnerText = activity.Appeal_name.ToString();
                //        this.lxfs.InnerText = activity.Appeal_tel;
                //    }
                //    else
                //    {
                //        this.xm.InnerText = "****信息已加密****";
                //        this.lxfs.InnerText = "****信息已加密****";
                //        //this.xm.InnerText = activity.Appeal_name.ToString();
                //        //this.lxfs.InnerText = activity.Appeal_tel;
                //    }
                //    this.lab_xbsj.InnerText = activity.Xbtime == new DateTime(1900, 01, 01, 00, 00, 00) ? "无限办时间" : activity.Xbtime.ToString();
                //    this.sjbh.InnerText = activity.Appealid.ToString();
                //    this.sbsj.InnerText = activity.Regtime.ToString();
                //    this.gs.InnerText = AscriptionManager.FindById(activity.Ascription_id).Name;
                //    this.dl.InnerText = Classification_Appeal1Manager.FindById(activity.Appeal_type_id).Name;
                //    this.xl.InnerText = Classification_Appeal2Manager.FindById(activity.Xialei).Name;
                //    this.yx.InnerText = activity.Appeal_email;
                //    this.bt.InnerText = activity.Title;
                //    this.nr.InnerText = activity.Context;
                //    this.gh.InnerText = activity.Jobnum.ToString();
                //    if (activity.Current_ld == 0)
                //    {
                //        dbm.InnerText = "一级部门办理中";
                //    }
                //    else if (activity.Current_ld == 1)
                //    {
                //        dbm.InnerText = "二级部门办理中";
                //    }
                //    else if (activity.Current_ld == 2)
                //    {
                //        dbm.InnerText = "三级部门办理中";
                //    }
                //    this.repeater.DataSource = Problem_historic2Manager.FindBysj(activity.Appealid);
                //    this.repeater.DataBind();
                //    this.div.Visible = false;

                //    if (Request.QueryString["type"].Equals("daiban"))
                //    {
                //    }
                //}
            }
        }
        catch (Exception ex)
        {


            Response.Write("<script>alert('登录信息已失效，请重新登录'); window.parent.location.href='/index.html'</script>");
            return;
        }


    }


    public String sjlx(int id)
    {
        String res = "";
        try
        {

            if (id == 0)
            {
                res = "受理";
            }
            else if (id == 1)
            {
                res = "派遣";
            }
            else if (id == 2)
            {
                res = "直办";
            }
            else if (id == 3)
            {
                res = "反馈";
            }
            else if (id == 4)
            {
                res = "审核";
            }
            else if (id == 5)
            {
                res = "驳回";
            }
            else if (id == 6)
            {
                res = "督办";
            }
            else if (id == 7)
            {
                res = "延期";
            }
            else if (id == 8)
            {
                res = "办结";
            }
            else if (id == 9)
            {
                res = "申请办结";
            }

        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登录信息已失效，请重新登录'); window.parent.location.href='/index.html'</script>");
            return "";
        }
        return res;
    }

    public String dwxx(String id)
    {
        try
        {
            String res = "";
            if (id.Length == 6)
            {
                if (DWManager.FindById(id) == null)
                {
                    res = ZS_TYPEINFOManager.FindById(id).NAME;
                }
                else
                {

                    res = DWManager.FindById(id).DWMC;
                }
            }
            else if (id.Length == 3 || id.Length == 2 || id.Length == 1)
            {
                if (ZS_TYPEINFOManager.FindById(id) != null)
                {
                    res = ZS_TYPEINFOManager.FindById(id).NAME;
                }
                else
                {
                    res = DWManager.FindById(id).DWMC;
                }

            }
            else
            {
                res = "无";
            }
            return res;
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登录信息已失效，请重新登录'); window.parent.location.href='/index.html'</script>");
            return "";
        }
    }
    protected void repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录信息已失效，请重新登录');window.parent.parent.location.href='/Login.aspx'</script>");
            }
            else
            {
                this.div.Visible = true;
                if (e.CommandName.Equals("links"))
                {
                    Problem_historic2 his2 = Problem_historic2Manager.FindById(Convert.ToInt32(e.CommandArgument));
                    this.lab_title.InnerText = his2.Title;
                    this.lab_slr.InnerText = his2.Name;
                    this.lab_hf.InnerText = his2.Blyj;
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登录信息已失效，请重新登录'); window.parent.location.href='/index.html'</script>");
            return;
        }

    }


    protected void Button1_Click(object sender, EventArgs e)
    {

        var name1 = DateTime.Now.ToString("yyyyMMddhhmmss") + new Random(DateTime.Now.Second).Next(10000);
        var path = Server.MapPath("~/xls_down/" + name1 + ".xlsx");

        //诉求人 性别 联系电话 诉求来源 诉求类型 诉求分类 诉求编号 办理工号
        //登记时间 责任单位 是否超时 转办时间 办理单位 申请延期 限办时间
        //诉求主题 拟办意见 诉求内容 办理结果 领导批示 一次驳回 二次驳回
        //一次督办 二次督办 满意情况 反馈人 

        string sqr = this.xm.InnerText.Trim().ToString();
        string xb = "";
        string lxdh = this.lxfs.InnerText.Trim().ToString();
        string sqly = this.sqly.InnerText.Trim().ToString();
        string sqlx = this.sqlx.InnerText.Trim().ToString();
        string sqfl = this.xl.InnerText.Trim().ToString();
        string sqbh = this.sjbh.InnerText.Trim().ToString();
        string blgh = this.gh.InnerText.Trim().ToString();
        string djsj = this.sbsj.InnerText.Trim().ToString();
        string zrdw = this.zrdwid.InnerText.Trim().ToString();
        string sfcs = this.is_cs.InnerText.Trim().ToString();
        string zbsj = "";
        string bldw = this.dbm.InnerText.Trim().ToString();
        string sqyq = this.sqyq.InnerText.Trim().ToString();
        string xbsj = this.lab_xbsj.InnerText.Trim().ToString();
        string sqzt = this.bt.InnerText.Trim().ToString();
        string nbyj = this.nbyj.InnerText.Trim().ToString();
        string sqnr = this.nr.InnerText.Trim().ToString();
        string bljg = this.bljg.InnerText.Trim().ToString();
        string ldps = "";
        string ycbh = "";
        string ecbh = "";
        string ycdb = "";
        string ecdb = "";
        string myqk = "";
        string fkr = "";
        string fhsj = "";

        ExcelHelper.x2007.ToExcelJLD(path, sqr, xb, lxdh, sqly, sqlx, sqfl, sqbh, blgh, djsj, zrdw, sfcs, zbsj, bldw, sqyq, xbsj, sqzt, nbyj, sqnr, bljg, ldps, ycbh, ecbh, ycdb, ecdb, myqk, fkr, fhsj);

        downloadfile(path);
    }

    void downloadfile(string s_path)
    {
        System.IO.FileInfo file = new System.IO.FileInfo(s_path);
        HttpContext.Current.Response.ContentType = "application/ms-download";
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
        HttpContext.Current.Response.Charset = "utf-8";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
        HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
        HttpContext.Current.Response.WriteFile(file.FullName);
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.End();
    }

    /// <summary>
    /// 不同意延期
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button2_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request.QueryString["id"]);
        Yqsqbty y = new Yqsqbty();
        y.Sjid = id;
        y.Sfzb = 0;
        //select_yqsq

        Yqsq yqsqInfo = YqsqManager.select_yqsq(Request.QueryString["id"].ToString(), ((USER_INFO)Session["users"]).DEPARTMENT);

        yqsqInfo.Bm1_type = 1;

        if (YqsqManager.Update(yqsqInfo) > 0) 
        {
            if (YqsqbtyManager.Save(y) > 0)
            {

                //Problem_historic2 his = new Problem_historic2();
                //his.Blyj = sqyy.Value.Trim().ToString();
                //his.Title = "申请延期 ";
                //his.Bm2 = "";
                //his.Evente = 7;
                //his.Idopen = this.sjbh.Value;


                //his.Bm1 = ((USER_INFO)Session["users"]).DEPARTMENT;
                //his.Item1 = 0;
                //his.Item2 = "";
                //his.Item3 = "";
                //his.Name = ((USER_INFO)Session["users"]).USER_NAME;
                //his.Times = DateTime.Now;
                //his.Timese = Convert.ToDateTime(this.times.Value);


                //Problem_historic2Manager.Save(his);

                Response.Write("<script>alert('提交成功');location.href='List_yq.aspx'</script>");
            }
            else
            {
                Response.Write("<script>alert('提交失败');</script>");
            }
        }

        
    }

    /// <summary>
    /// 同意延期
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button3_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request.QueryString["id"]);
        
        Yqsq yqsqInfo = YqsqManager.select_yqsq(Request.QueryString["id"].ToString(),((USER_INFO)Session["users"]).DEPARTMENT);

        yqsqInfo.Bm1_type = 0;

        if (YqsqManager.Update(yqsqInfo) > 0)
        {
            //Problem_historic2 his = new Problem_historic2();
            //his.Blyj = sqyy.Value.Trim().ToString();
            //his.Title = "申请延期 ";
            //his.Bm2 = "";
            //his.Evente = 7;
            //his.Idopen = this.sjbh.Value;


            //his.Bm1 = ((USER_INFO)Session["users"]).DEPARTMENT;
            //his.Item1 = 0;
            //his.Item2 = "";
            //his.Item3 = "";
            //his.Name = ((USER_INFO)Session["users"]).USER_NAME;
            //his.Times = DateTime.Now;
            //his.Timese = Convert.ToDateTime(this.times.Value);


            //Problem_historic2Manager.Save(his);

            Response.Write("<script>alert('提交成功');location.href='List_yq.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('提交失败');</script>");
        }
    }

    //延期至
    public string select_yqz(string i)
    {
        string s = "";
        try
        {
            Yqsq y = YqsqManager.select_Foridopen(i);
            return y.Times.ToString();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return s;
        }
    }
}